/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "S_Object.h"

#include "S_键值序列容器.h"


static S_键值序列容器<uint32, S_Object*> g_物体容器;
static S_键值序列容器<uint32, S_物理体*> g_物理体容器;

C_Key分配器		S_Object::m_ID生成器;
C_StrKey分配器	S_物理几何体::g_名称生成器;
C_StrKey分配器	S_物理体::g_名称生成器;


S_Object::S_Object(E_物体类型 type, uint32 key) : m_Type(type) {
	m_ID = key;
	m_globalID = m_ID生成器.f_Gen();

	m_是否展开 = false;
	m_可拾取 = true;
	m_显示 = true;
	m_选中 = false;

	m_层数量 = 0;
	m_层深度 = 0;

	m_父对象 = nullptr;
	m_UserData = nullptr;
}
S_Object::~S_Object() {
	m_ID生成器.f_Move(m_globalID);
}


S_物理体::S_物理体(S_物理几何体* geom, uint32 key, std::u16string name) : S_Object(E_物体类型::t_物理体, key) {
	
	m_Data = nullptr;
	m_构建更新 = false;

	m_粒子偏移和数量 = {};
	//m_速度块区 = {};
	//m_质量块区 = {};

	m_绑定物体				= nullptr;
	m_虚拟链接轴绑定物体	= nullptr;
	m_几何体 = geom;
	mf_销毁 = nullptr;
	m_物理体类型 = E_物理体类型::E_物理体_空;
	m_物理引擎枚举 = E_物理引擎::E_物理引擎_Mujoco;

	m_链接类型 = E_物理体链接类型::e_自由;
	m_链接轴向 = {1,0,0};
	m_链接坐标偏移 = {};

	m_限定范围 = false;
	m_关节范围 = {-1,1};
	m_关节阻尼 = 0.2;
	m_关节刚度 = 0.2;
	m_关节摩擦 = 0.1;

	m_密度 = 0.1;

	f_TranformInit(m_变换);
	m_Name = name;
	//m_Name = g_名称生成器.f_Gen(name);
}

S_物理体::~S_物理体() {
	//g_名称生成器.f_Move(m_Name);
}

S_物理体* S_物理体::f_get(uint32 key) {
	return 0;
}

void S_物理体::f_set绑定物体矩阵(const Mat44f& mat) {
	
}

E_物体类型 f_ob_以名称取类型(std::wstring name) {
	E_物体类型 类型 = E_物体类型::t_空;



	return 类型;
}

E_物体类型 f_ob_以名称索引取类型(uint32 index) {
	switch (index) {
		case 0: return E_物体类型::t_网格物体;
		case 1: return E_物体类型::t_平行光;
		case 2: return E_物体类型::t_点光源;
		case 3: return E_物体类型::t_区域光;
		case 4: return E_物体类型::t_聚光灯;
		case 5: return E_物体类型::t_摄像机;
		case 6: return E_物体类型::t_虚拟体;

		case 7: return E_物体类型::t_多边形;
		default:
			break;
	}
	return E_物体类型();
}



S_Object* f_ob_查找父对象(S_Object* ob, E_物体类型 type) {
	if (ob->m_Type == type) {
		return ob;
	}
	if(ob->m_父对象){
		return f_ob_查找父对象(ob->m_父对象, type);
	}
	return nullptr;
}
